package com.zz.man.handle;

import com.zz.man.domian.Result;
import com.zz.man.exception.ManException;
import com.zz.man.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;



@ControllerAdvice
public class ExceptionHandle {
    private final static Logger logger = (Logger) LoggerFactory.getLogger(ExceptionHandle.class);
    @ExceptionHandler(value =  Exception.class)
    @ResponseBody
    public Result handler(Exception e){
        if (e instanceof ManException){
            ManException e1 = (ManException)e;
            return ResultUtil.error(e1.getCode(),e1.getMessage());
        }else {
            logger.error("【系统异常】",e);
            return ResultUtil.error(200, "未知错误");
        }
    }
}
